package controllers

import (
	"github.com/goravel/framework/contracts/http"
	"github.com/goravel/framework/facades"
	httpfacade "github.com/hulutech-web/http_result"
	"goravel/app/models"
)

type RoleController struct {
	//Dependent services
}

func NewRoleController() *RoleController {
	return &RoleController{
		//Inject services
	}
}

// Index 用户分页查询，支持搜索，路由参数?name=xxx&pageSize=1&currentPage=1&sort=xxx&order=xxx,等其他任意的查询参数
// @Summary      用户分页查询
// @Description  用户分页查询
// @Tags         RoleController
// @Accept       json
// @Produce      json
// @Id RoleIndex
// @Security ApiKeyAuth
// @Param Authorization header string false "Bearer 用户令牌"
// @Param  name  query  string  false  "name"
// @Param  pageSize  query  string  false  "pageSize"
// @Param  currentPage  query  string  false  "currentPage"
// @Param  sort  query  string  false  "sort"
// @Param  order  query  string  false  "order"
// @Success 200 {string} json {}
// @Router       /api/admin/role [get]
func (r *RoleController) Index(ctx http.Context) http.Response {
	roles := []models.Role{}
	var total int64
	facades.Orm().Query().Model(&models.Role{}).OrderBy("id", "desc").Paginate(1, 10, &roles, &total)
	return httpfacade.NewResult(ctx).Success("", roles)
}
